/**
 * @param {number} x
 * @param {number} n
 * @return {number}
 */
var myPow = function (x, n) {
  let res = x
  if (n === 0) return 1
  // let res
  else if (n > 0) {
    while (n != 1) {
      res *= x
      n--
    }
  } else {
    while (Math.abs(n) != 0) {
      res /= x
      n++
    }
  }
  return res
}

console.log(myPow(2.0, -2))
